using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using QFramework;
using UnityEngine.UI;

namespace ProjectMyFarmAndShe
{
	public partial class ToolbarPanel : ViewController,IController
	{
		private IToolbarSystem mSystem;

		public List<ToolbarItemTemplate> ToolbarItemTemplates = new List<ToolbarItemTemplate>();
		
		private void Awake()
		{
			mSystem = this.GetSystem<IToolbarSystem>();
		}

		void Start()
		{
			// Code Here

			for (var i = 0; i < mSystem.ToolbarDatas.Count; i++)
			{
				var data = mSystem.ToolbarDatas[i];
				var shortcut = i + 1;
				var item = ToolbarItemTemplate.InstantiateWithParent(Root)
					.Self(self =>
					{
						var cache = data;
						
						self.Init(cache,shortcut);
					})
					.Show();
				
				ToolbarItemTemplates.Add(item);
			}

			ActionKit.NextFrame(() =>
				{
					Global.Tool = ToolbarItemTemplates[0].ItemData.Tool;
					Global.OnToolChange.Trigger(Global.Tool);
				})
				.StartCurrentScene();
		}

		public IArchitecture GetArchitecture()
		{
			return Global.Interface;
		}
	}
}
